<?php
/**
 * Created by laoyu.
 * User: hilaoyu@qq.com
 * Date: 2018/5/22
 * Time: 17:11
 */

namespace Hilaoyu\LaravelExtend\Providers;

use Hilaoyu\LaravelExtend\Services\Assents\AssentsExcludeRouteMiddleware;
use Hilaoyu\LaravelExtend\Supports\SubApp;
use Illuminate\Support\ServiceProvider;
class AssentsServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->publishes([
            $this->configPath() => config_path('assents.php'),
        ]);




        //dd(\Route::getRoutes());

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->mergeConfigFrom($this->configPath(), 'assents');
        $this->app->router->aliasMiddleware('assents_route_exclude', AssentsExcludeRouteMiddleware::class);

        $this->loadViewsFrom(dirname(__DIR__).'/views', 'LaravelExtend');

        foreach (config('assents.route_connectors',[]) as $route_key => $route_config){
            data_set($route_config,'name','l-e-s.assents.'.$route_key);
            data_set($route_config,'prefix','_les/assents/'.$route_key);

            SubApp::registerRoutes(dirname(__DIR__) . '/Services/Assents/routes','Hilaoyu\\LaravelExtend\\Services\\Assents\\Controllers',$route_config);
        }
    }

    protected function configPath()
    {
        return dirname(__DIR__) . '/Services/Assents/config/assents.php';
    }
}
